package cn.ddd.linktran.application.service;

import cn.ddd.linktran.application.executor.command.UrlMapAddCmdExe;
import cn.ddd.linktran.client.api.UrlMapService;
import cn.ddd.linktran.client.dto.cmd.UrlMapAddCmd;
import cn.ddd.linktran.client.dto.data.UrlMapDTO;
import cn.ddd.linktran.client.dto.query.LongByShortQry;
import com.alibaba.cola.dto.SingleResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@Primary
public class UrlMapServiceImpl implements UrlMapService {
    @Autowired
    private UrlMapAddCmdExe urlMapAddCmdExe;
    @Override
    public SingleResponse<UrlMapDTO> createUrlMap(UrlMapAddCmd urlMapAddCmd) {
        if (Objects.isNull(urlMapAddCmd) || StringUtils.isEmpty(urlMapAddCmd.getLongUrl()) || StringUtils.isEmpty(urlMapAddCmd.getDescription()))
            throw new IllegalArgumentException("longUrl and description can't be empty");
        return urlMapAddCmdExe.execute(urlMapAddCmd);
    }

    @Override
    public SingleResponse<UrlMapDTO> getLongByShort(LongByShortQry longByShortQry) {
        // TODO
        return null;
    }
}
